(*factorial*)

Clear["`*"];

{10!, Factorial[10]}

1000!;//Timing

fact1[n_]:=Gamma[n+1]

fact1[10]

fact2[n_]:=Module[{x=0,z=1},
If[n==0,1,While[!(x==n),x=x+1;z=z*x]];z]

fact2[10]

fact3:=Function[{n},Module[{i=1,f=1},While[i<n,i++;f=f*i];f]];

fact3[10]

fact4[n_ ]:=If[n==0,1,n*fact4[n-1]]

f=Array[fact4,10]

f[[10]]

Trace[fact4[3]]

Trace[fact4[3],fact4[n_]]

Trace[fact4[3],fact4[n_]->n!]

Trace[fact4[3],_==_]

fact5[0]=1;
fact5[n_]:=n*fact5[n-1]

fact5[10]

?fact5

fact6[0]=1;
fact6[n_]:=fact6[n]=n*fact6[n-1]

fact6[10]

?fact6

fact7[n_]:=Times@@Range[n]

fact7[10]

FoldList[Times, 1, Range[10]]

Fold[Times, 1, Range[10]]

$RecursionLimit

fact4[500]

$RecursionLimit=1010

{"fact1", (Timing[fact1[1000];] /. Second->1)[[1]]}
{"fact2", (Timing[fact2[1000];] /. Second->1)[[1]]}
{"fact3", (Timing[fact3[1000];] /. Second->1)[[1]]}
{"fact4", (Timing[fact4[1000];] /. Second->1)[[1]]}
{"fact5", (Timing[fact5[1000];] /. Second->1)[[1]]}
{"fact6", (Timing[fact6[1000];] /. Second->1)[[1]]}
{"fact6", (Timing[fact6[1000];] /. Second->1)[[1]]}
{"fact7", (Timing[fact7[1000];] /. Second->1)[[1]]}

Clear[fact6]
fact6[0]=1;
fact6[n_]:=fact6[n]=n*fact6[n-1]

FactorialFunctions={fact1,fact2,fact3,fact4,fact5,fact6,fact6,fact7}

fact3
FactorialFunctions

Map[{#, (Timing[#[1000];] /. 
			Second->1)[[1]]}&,FactorialFunctions]//TableForm

FactorialFunctions={"fact1","fact2","fact3","fact4","fact5","fact6","fact6","fact7"}

Map[{#, (Timing[ToExpression[#][1000];] /. 
			Second->1)[[1]]}&,FactorialFunctions]//TableForm

$RecursionLimit=256

factA[n_Integer ]:=If[n==0,1,n factA[n-1]]

{factA[-1],factA[2.5],factA[0],factA[10]}

factB[n_Integer?NonNegative]:=If[n==0,1,n factB[n-1]]

{factB[-1],factB[2.5],factB[0],factB[10]}

factC[n_Integer/; n>=0]:=If[n==0,1,n factC[n-1]]

{factC[-1],factC[2.5],factC[0],factC[10]}

?fact5